/*
 * Created by JFormDesigner on Thu May 26 14:41:08 CST 2022
 */

package jw3.c2.view;

import java.awt.event.*;

import jw3.c2.controller.CustomerController;
import jw3.c2.controller.OpensController;

import java.awt.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 * @author Brainrain
 */
public class H1 extends JFrame {
    public H1() {
        initComponents();
        setLocation(500,200);
        setSize(1150,800);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
    }
    //1、全查  2、模糊查
    private void showData(String U_Name){
        //方式一：一维数组作为表头、二维数组作为数据  缺陷:需要初始化长度、无法动态增删

        //方式二: 给表格设置模型,使用Vector<Object>完成
        //1、表头
        Vector<Object> heads=new Vector<Object>();
        heads.add("客户编号");
        heads.add("宾客姓名");
        heads.add("性别");
        heads.add("证件编号");
        heads.add("证件类型");
        heads.add("详细地址");

        //2、表数据
//        Vector<UserInfo> data= UserInfoController.getAll();
        data= CustomerController.getAll(U_Name);
        //3、将表头和数据赋值给模型，表格模型构造完成
        DefaultTableModel dtm=new DefaultTableModel(data,heads);
        table1.setModel(dtm);
        //table1=new JTable(dtm);   等同上面，但会增加开销
    }
    private void menu2MouseClicked(MouseEvent e) {
        // TODO add your code here
        H2 h=new H2();
        setVisible(false);
    }

    private void menu1MouseClicked(MouseEvent e) {
        // TODO add your code here
        H1 h1=new H1();
        setVisible(false);
    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        showData(textField1.getText());
    }

    private void button2MouseClicked(MouseEvent e) {
        // TODO add your code here
        showData(textField1.getText());
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        menuBar1 = new JMenuBar();
        menu1 = new JMenu();
        menu2 = new JMenu();
        label1 = new JLabel();
        textField1 = new JTextField();
        button1 = new JButton();
        button2 = new JButton();
        panel1 = new JPanel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        label2 = new JLabel();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== menuBar1 ========
        {

            //======== menu1 ========
            {
                menu1.setText("\u6765\u5bbe\u4fe1\u606f\u4e00\u89c8\u8868");
                menu1.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        menu1MouseClicked(e);
                    }
                });
            }
            menuBar1.add(menu1);

            //======== menu2 ========
            {
                menu2.setText("\u4f1a\u5458\u57fa\u672c\u4fe1\u606f\u7ef4\u62a4");
                menu2.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        menu2MouseClicked(e);
                    }
                });
            }
            menuBar1.add(menu2);
        }
        setJMenuBar(menuBar1);

        //---- label1 ----
        label1.setText("\u6765\u5bbe\u59d3\u540d/\u8bc1\u4ef6\u7f16\u53f7\uff1a");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(45, 50), label1.getPreferredSize()));
        contentPane.add(textField1);
        textField1.setBounds(195, 43, 130, textField1.getPreferredSize().height);

        //---- button1 ----
        button1.setText("\u67e5\u8be2");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(360, 43), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u5237\u65b0");
        button2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button2MouseClicked(e);
            }
        });
        contentPane.add(button2);
        button2.setBounds(new Rectangle(new Point(480, 43), button2.getPreferredSize()));

        //======== panel1 ========
        {
            panel1.setLayout(new BorderLayout());

            //======== scrollPane1 ========
            {
                scrollPane1.setViewportView(table1);
            }
            panel1.add(scrollPane1, BorderLayout.CENTER);
        }
        contentPane.add(panel1);
        panel1.setBounds(5, 170, 1115, 150);

        //---- label2 ----
        label2.setText("text");
        label2.setIcon(new ImageIcon("C:\\Users\\\u5c0f\u6797\\Desktop\\B.jpg"));
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(0, -50), label2.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        showData("");
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JMenuBar menuBar1;
    private JMenu menu1;
    private JMenu menu2;
    private JLabel label1;
    private JTextField textField1;
    private JButton button1;
    private JButton button2;
    private JPanel panel1;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JLabel label2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
    private static Vector<Vector<Object>> data;
}
